package com.yicong.ants.scenic.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.x.livesdk.BaseDataBindingHolder
import com.yicong.ants.R
import com.yicong.ants.databinding.ScenicOrderListItemBinding
import com.yicong.ants.scenic.data.TicketOrder

class ScenicOrderListAdapter :
    BaseQuickAdapter<TicketOrder, BaseDataBindingHolder<ScenicOrderListItemBinding>>(R.layout.scenic_order_list_item) {
    init {
        setEnableLoadMore(false)
    }

    var refreshListener: (() -> Unit)? = null
    var callback: Callback? = null

    override fun addData(newData: MutableCollection<out TicketOrder>) {
        super.addData(newData)
        if (data.isEmpty()) {
            setEmptyView(R.layout.empty_view_a)
            emptyView?.findViewById<View>(R.id.refreshBtn)?.setOnClickListener {
                refreshListener?.invoke()
            }
        }
    }

    override fun convert(
        holder: BaseDataBindingHolder<ScenicOrderListItemBinding>,
        item: TicketOrder
    ) {
        holder.dataBinding?.data = item
        when (item.orderStatus) {
            "4", "99" -> {
                holder.dataBinding?.controlBtn?.text = "再次预约"
                holder.dataBinding?.controlBtn?.setOnClickListener {
                    callback?.onReorderBtnClick(item)
                }
            }

            else -> {
                holder.dataBinding?.controlBtn?.text = "查看详情"
                holder.dataBinding?.controlBtn?.setOnClickListener {
                    callback?.onDetailBtnClick(item)
                }
            }
        }
    }

    interface Callback {
        fun onReorderBtnClick(item: TicketOrder)
        fun onDetailBtnClick(item: TicketOrder)
    }
}